package com.qdu.web.controller.bussiness;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qdu.common.annotation.Log;
import com.qdu.common.core.controller.BaseController;
import com.qdu.common.core.domain.AjaxResult;
import com.qdu.common.enums.BusinessType;
import com.qdu.bussiness.domain.BusEntry;
import com.qdu.bussiness.service.IBusEntryService;
import com.qdu.common.utils.poi.ExcelUtil;
import com.qdu.common.core.page.TableDataInfo;

/**
 * 入库记录Controller
 * 
 * @author qdu
 * @date 2022-03-05
 */
@RestController
@RequestMapping("/bussiness/entry")
public class BusEntryController extends BaseController
{
    @Autowired
    private IBusEntryService busEntryService;

    /**
     * 查询入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('bussiness:entry:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusEntry busEntry)
    {
        startPage();
         List<BusEntry> list = busEntryService.selectBusEntryList(busEntry);
        return getDataTable(list);
    }

    /**
     * 导出入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('bussiness:entry:export')")
    @Log(title = "入库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusEntry busEntry)
    {
        List<BusEntry> list = busEntryService.selectBusEntryList(busEntry);
        ExcelUtil<BusEntry> util = new ExcelUtil<BusEntry>(BusEntry.class);
        util.exportExcel(response, list, "入库记录数据");
    }

    /**
     * 获取入库记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('bussiness:entry:query')")
    @GetMapping(value = "/{entryId}")
    public AjaxResult getInfo(@PathVariable("entryId") Long entryId)
    {
        return AjaxResult.success(busEntryService.selectBusEntryByEntryId(entryId));
    }

    /**
     * 新增入库记录
     */
    @PreAuthorize("@ss.hasPermi('bussiness:entry:add')")
    @Log(title = "入库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusEntry busEntry)
    {
        return busEntryService.insertBusEntry(busEntry);
    }

    /**
     * 修改入库记录
     */
    @PreAuthorize("@ss.hasPermi('bussiness:entry:edit')")
    @Log(title = "入库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusEntry busEntry)
    {
        return busEntryService.updateBusEntry(busEntry);
    }

    /**
     * 删除入库记录
     */
    @PreAuthorize("@ss.hasPermi('bussiness:entry:remove')")
    @Log(title = "入库记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{entryIds}")
    public AjaxResult remove(@PathVariable Long[] entryIds)
    {
        return toAjax(busEntryService.deleteBusEntryByEntryIds(entryIds));
    }

    /**
     * 修改入库单状态
     * @param entryId
     * @param entryStauts
     * @return
     */
    @GetMapping("/changeStatus/{entryId}/{entryStauts}")
    public AjaxResult changeEntryStatus(@PathVariable Long entryId, @PathVariable String entryStauts){
        return busEntryService.changeEntryStatus(entryId, entryStauts);
    }

    /**
     * 确认入库
     * @param entryId
     * @return
     */
    @GetMapping("/ensure/{entryId}")
    public AjaxResult ensureEntry(@PathVariable Long entryId){
        return busEntryService.ensureEntry(entryId);
    }
}
